using System.Collections.ObjectModel;
using Company.IntegrationTestDslLanguage;
using DslCrossModelFramework;
using DslCrossModelFramework.Environment;
using Microsoft.VisualStudio.Modeling;
using Xunit;

namespace UnitTest.xUnitTests.CrossModelFramework {
    public class CrossModelProxyTests {

        /// <summary>
        /// Tests the resolution of all External Class proxy elements.
        /// </summary>
        [Fact]
        public void ResolveExternalClassProxyElements() {
            TestHelper.RegisterEnvironmentConfiguration();
            CrossModelManager manager = new CrossModelManager();
            manager.GetModelDirectory().PreloadAllModelFiles();
            EnvironmentConfiguration.Current.GetModelDirectory().PreloadAllModelFiles();

            // Search the Model Directory for a proxy element
            IModelDirectory directory = EnvironmentConfiguration.Current.GetModelDirectory();
            ReadOnlyCollection<ModelElement> externalClasses = directory.FindAllElements(ExternalClass.DomainClassId);

            Assert.NotEqual(0, externalClasses.Count);

            foreach(ModelElement mel in externalClasses) {
                ExternalClass externalClass = mel as ExternalClass;

                // Test that the Target element can be found
                Assert.NotNull(externalClass.TargetPath.TargetModelElement);
                Assert.IsType<ModelingClass>(externalClass.TargetPath.TargetModelElement);
            }
        }
    }
}